package com.zhao.tongcheng.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import com.zhao.tongcheng.dto.Scenery;

public class SceneryDao extends Manager {
	public int insert(Scenery scenery)
	{
		Connection conn = null;
		PreparedStatement ps = null;
		
		String sql = "insert into  lv_scenery ( `sceneryId`, `sceneryName`,  `grade`,`address`,`cityId`,`provinceId`,`intro`,`buyNotice`,`payMode`,`lon`,`lat`) " +
				"VALUES  (?,?,?,?,? ,?,?,?,?,? ,?) ";
		int ret=1;
		String pwd="";
		Calendar calendar = Calendar.getInstance();
		Date date = calendar.getTime();

		SimpleDateFormat ymdhmsf = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		String reqTime = ymdhmsf.format(date);
		conn = getConnectionBy();
		if (conn != null) {
			try {
				ps = conn.prepareStatement(sql);
				ps.setString(1, scenery.getSceneryId());
				ps.setString(2,scenery.getSceneryName());
				ps.setString(3, scenery.getGrade());				
				ps.setString(4, scenery.getAddress());
				
				ps.setString(5, scenery.getCityId());
				ps.setString(6,scenery.getProvinceId());
				ps.setString(7, scenery.getIntro());				
				ps.setString(8, scenery.getBuyNotice());
				
				ps.setString(9, scenery.getPayMode());
				ps.setString(10,scenery.getLon());
				ps.setString(11, scenery.getLat());				
				
				
				ps.executeUpdate();
				ps.close();
				conn.close();
				ret=0;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				ret=3;
			}

		}
		return ret;
	}
}
